<template>
  <div>
    <van-nav-bar
        title="中国人民公安大学图书馆选座"/>
    <div style="text-align: center;padding-top: 20px">
      <van-image
          round
          width="10rem"
          height="10rem"
          :src='logo'
      />
      <van-form @submit="onLogin">
        <van-field
            v-model="loginParam.username"
            name="学号/工号"
            label="学号/工号"
            placeholder="学号/工号"
            :rules="[{ required: true, message: '请填写学号/工号' }]"
        />
        <van-field
            v-model="loginParam.password"
            type="password"
            name="密码"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button @click="onLogin" round block type="info" native-type="submit">登录</van-button>
        </div>
      </van-form>

    </div>


  </div>

</template>

<script>
import {login} from '@/api/login'
import {setToken} from "@/utils/auth";
import logo from "@/assets/logo.png"

export default {

  name: "Login",
  data(){
    return{
      logo:logo,
      loginParam:{
        username:"",
        password:""
    }
    }
  },
  methods:{
    onLogin(){
      login(this.loginParam).then(response => {
        setToken(response.data.tokenHead+" "+response.data.token)
        this.$router.push('/home')
      })

    }
  }
}
</script>

<style scoped>

</style>
